package com.ittx.dzt.baidu.consumer.area;

import com.ittx.dzt.baidu.constant.BaiduApiConstant;
import com.ittx.dzt.baidu.dto.AreaData;
import com.ittx.dzt.baidu.service.BaiduAreaDownloadSpService;
import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.sys.response.Result;
import com.ittx.dzt.sys.util.json.JacksonTool;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 区域地址数据消费
 * <p>
 *
 * </p>
 *
 * @author wl_code@163.com
 * @version 1.0
 * @date 2025/3/4
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = BaiduApiConstant.Rocket.BAIDU_SEND_AREA_GROUP,
		topic = BaiduApiConstant.Rocket.BAIDU_SEND_AREA_TOPIC)
public class BaiduAreaSendConsumer implements RocketMQListener<String> {
	@Autowired(required = false)
	BaiduAreaDownloadSpService baiduAreaDownloadSpService;

	@Override
	public void onMessage(String message) {
		try {
			// 单条处理消费
			AreaData areaData = JacksonTool.toEntity(message, AreaData.class);
			PlatformApiParamDTO platformApiParam = areaData.getPlatformApiParamDTO();
			// 下发的数据去除
			areaData.setPlatformApiParamDTO(null);
			Result<?> result = baiduAreaDownloadSpService.sendRequestToPlatform(platformApiParam, areaData, true);
			if (result.hasError()) {
				return;
			}
			if (result.hasError()) {
				log.error("百度区域地址数据处理后:[{}]推送数据失败:[{}]", message, result.getMsg());
			}
		} catch (Exception e) {
			log.error("百度区域地址数据处理消费者入参:[{}]", message);
			log.error("百度区域地址数据处理请求异常", e);
		}

	}
}
